<template>
    <div class="success-buy-container">
    <div class="logo-container">
    <img src="../assets/img/logo.webp" alt="图片" class="logo" ></img>
    <h1 class="success-buy">恭喜您，购买成功！</h1>
    </div>
    <el-button type="primary" @click="back" class="back">返回首页</el-button>
    </div>
    </template>
    
<script>
import axios from 'axios';
export default {
  methods:{
    async back() {
  try {
    const orderId = Number(this.$route.query.orderId); // 获取传递的订单ID并转换为数值类型
    console.log(`Updating order status for order ID: ${orderId}`); // 添加调试信息
    const response = await axios.post('http://localhost:8080/api/orders/updateStatus', { orderId: orderId, status: '已支付' });
    console.log("Order status updated successfully", response.data); // 添加调试信息
    this.$router.push('/mainpage');
  } catch (error) {
    console.error("Error updating order status:", error.response ? error.response.data : error.message);
    if (error.response) {
      console.error("Response data:", error.response.data);
      console.error("Response status:", error.response.status);
      console.error("Response headers:", error.response.headers);
    }
  }
}
  }
}
</script>
    
    <style scoped>
    .success-buy-container{
        justify-content: center;
        align-items: center;
    }
    .logo-container{
        display: flex;
        justify-content: center;
        margin-top: 20%;
        gap: 10px;
    }
    .success-buy{
        color: red;
        font-size: 50px;
    }
    .logo{
        width: 200px;
        height: 150px;
    }
    .back{
        margin-left: 50%;
    }
    </style>